package org.magicbox.qjunTPO.controller;


import org.magicbox.qjunTPO.common.lang.Result;
import org.magicbox.qjunTPO.entity.Poems;
import org.magicbox.qjunTPO.service.PoemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 欢迎添加科技实践队粉丝群：690849711
 * @since 2021-11-12
 */
@RestController
@RequestMapping("/poems")
public class PoemsController {

    @Autowired
    private PoemsService service ;
    @RequestMapping("/add")
    public Result add(@Validated @RequestBody Poems poem){
        LocalDateTime birthData = LocalDateTime.now();
        poem.setBirthData(birthData);
        return Result.success(service.save(poem));
    }

    public boolean requestadd(Integer id){
        Poems poems = service.getById(id);
        poems.setRequestSum(poems.getRequestSum()+1);
        boolean upok = service.updateById(poems);
        if(upok) return true;
        return false;
    }

    public Integer byIdGetUid(Integer id){
        return service.getById(id).getUid();
    }
}
